package day15.ZiXi;

import java.util.concurrent.ArrayBlockingQueue;

public class Cooker02 extends Thread{
    private ArrayBlockingQueue<String> bd;
    public Cooker02(ArrayBlockingQueue<String> bd){
        this.bd = bd;
    }

    @Override
    public void run() {
        while (true){
            try {
                bd.put("小汉堡");
                System.out.println("厨师放入一个汉堡");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class Foodie02 extends Thread{
    private ArrayBlockingQueue<String> bd;
    public Foodie02(ArrayBlockingQueue<String> bd){
        this.bd = bd;
    }

    @Override
    public void run() {
        while (true){
            try {
                String take = bd.take();
                System.out.println("吃货将" + take + "拿出来吃了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
class Demo03{
    public static void main(String[] args) {
        ArrayBlockingQueue<String> arr = new ArrayBlockingQueue<>(1);
        Foodie02 f = new Foodie02(arr);
        Cooker02 c = new Cooker02(arr);
        f.start();
        c.start();
    }
}